<template>
  <div class="login">
    <div class="canvas"></div>
    <div class="form">
    <div class="headerName">
      应急事件后台管理系统
    </div>
    <el-form
      :rules="rules"
      class="login-container"
      label-position="left"
      label-width="80px"
      v-loading="loading"
    >
    <!-- <p class="decorate"></p> -->
      <h3 class="login_title">登录</h3>

      <el-form-item prop="username" label="账号:">
        <el-input
          type="text"
          v-model="loginForm.username"
          auto-complete="off"
          placeholder="账号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item prop="password" label="密码:">
        <el-input
          type="password"
          v-model="loginForm.password"
          auto-complete="off"
          placeholder="密码"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="身份:" prop="radio">
        <el-radio-group v-model="loginForm.radio">
          <el-radio label="1">管理员</el-radio>
          <el-radio label="2">物资调配员</el-radio>
        </el-radio-group>
      </el-form-item>

      <!-- <el-radio-group v-model="radio" style="margin-bottom: 15px">
      <el-radio :label="3">病人</el-radio>
      <el-radio :label="6">医生</el-radio>
      <el-radio :label="9">管理员</el-radio>
    </el-radio-group> -->
      <!--    <el-checkbox class="login_remember" v-model="checked" label-position="left">记住密码</el-checkbox>-->
      <el-form-item style="width: 100%" label-width="0">
        <el-button
          type="primary"
          plain
          round
          @click.native.prevent="submitClick"
          style="width: 50%"
          >登 录</el-button
        >
      </el-form-item>
    </el-form>
    </div>
  </div>
</template>
<script>
import "../css/Login.css";
import axios from 'axios'

export default {
  data() {
    return {
      rules: {
        username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }], //提示信息
        radio: [{ required: true, message: '请选择身份', trigger: 'blur' }],
      },
      checked: true, //默认勾选
      loginForm: {
        //默认input
        username: "1987136",
        password: "123456",
        radio:"1",
      },
      loading: false,
    };
  },
  methods: {
    submitClick: function () {
      console.log(this.radio);
      this.loading = true; //显示加载
      axios.get('/manager/login?account='+this.loginForm.username+'&password='+this.loginForm.password).then((resp) => {
            if (resp.status == 200) {
                this.$message({
                message: '登录成功',
                type: 'success'
                });   
                this.loading=false
                if(this.loginForm.radio=="1"){
                  this.$router.replace({ path: "/home" });
                }else{
                  this.$router.replace({ path: "/goods" });
                }
            }
      },(error)=>{
            this.$message.error(error);
            this.$alert("账号或密码错误");
            this.loading=false
      })


      // postRequest("/login", {
      //   //发送请求
      //   username: this.loginForm.username,
      //   password: this.loginForm.password,
      //   type: this.radio,
      // }).then(
      //   (resp) => {
      //     _this.loading = false; //请求成功
      //     if (resp.status == 200) {
      //       //成功
      //       var json = resp.data;
      //       if (json.status == "success") {
      //         _this.$router.replace({ path: "/home" }); //跳转到home
      //       } else {
      //         _this.$alert("登录失败!", "失败!");
      //       }
      //     } else {
      //       //失败
      //       _this.$alert("登录失败!", "失败!");
      //     }
      //   },
      //   (resp) => {
      //     _this.loading = false;
      //     // _this.$alert("找不到服务器⊙﹏⊙∥!", "失败!");
      //     _this.$alert("登录成功！","成功");
      //     _this.$router.replace({ path: "/home" }); //跳转到home
      //   }
      // );
    },
  },
};
</script>
<style>

</style>
